<html>
<head><meta charset="utf-8"><title>label scoping · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/label.20scoping.html">label scoping</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207214223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/label%20scoping/near/207214223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/label.20scoping.html#207214223">(Aug 18 2020 at 01:04)</a>:</h4>
<p>While waiting for <a href="https://github.com/rust-lang/rfcs/pull/2046">https://github.com/rust-lang/rfcs/pull/2046</a> to land (for years...), I use loops with a break to mimic labeled break. (And get yelled at by clippy...) But as a result I found an unusual aspect of loop labels:</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"> </span><span class="na">&#39;a</span>: <span class="nc">loop</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="nl">&#39;a</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"> </span><span class="na">&#39;a</span>: <span class="nc">loop</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="nl">&#39;a</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>gives an error saying that the second <code>'a:</code> shadows another label in scope, but</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"> </span><span class="na">&#39;a</span>: <span class="nc">loop</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="nl">&#39;a</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"> </span><span class="na">&#39;b</span>: <span class="nc">loop</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="nl">&#39;a</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>is not valid. Are there scoping rules for labels?</p>



<a name="207231696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/label%20scoping/near/207231696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/label.20scoping.html#207231696">(Aug 18 2020 at 07:44)</a>:</h4>
<p>A recent similar thread - <a href="#narrow/stream/122651-general/topic/loop.20label.20shadowing.20confusion/near/204634010">https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/loop.20label.20shadowing.20confusion/near/204634010</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>